import java.math.BigInteger;
import java.util.Random;


public class DhServer {
	private int x, g, n;
	private  BigInteger A, B, S;
	private Random rand = new Random();

	public DhServer() {
	
		
		n = getPrimo();
		x = (int)(Math.random()*500);
		x += 25;
		g = rand.nextInt();
		//gerar g menor que n
			
		while (g > n) {
			g = rand.nextInt();
		}
		
		if (g<0)
			g*=-1;
		if (x<0)
			x*=-1;
		if (n<0)
			n*=-1;
		
		
		A = new BigInteger(new Integer(g).toString());
		A = A.pow(x);
		A = A.mod(new BigInteger(new Integer(n).toString()));
	
	}
	
	private int getPrimo() {
		int x=0;
		double resultado;
		boolean primo = false;
		do {
			x = rand.nextInt();
			
			for (int i=2; i<x; i++) {
				resultado = x % i;
				if (resultado == 0) {
					primo = false;
					break;
				}
				else {
					primo = true;
				
				}
			}
		}while (!primo);
		return x;
	}



	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getN() {
		return n;
	}

	public void setN(int n) {
		this.n = n;
	}	
	public int getG() {
		return g;
	}

	public void setG(int g) {
		this.g = g;
	}

	public BigInteger getA() {
		return A;
	}

	public void setA(BigInteger a) {
		A = a;
	}

	public BigInteger getB() {
		return B;
	}

	public void setB(BigInteger b) {
		B = b;
		S = B.pow(x);
		S = S.mod(new BigInteger(new Integer(n).toString()));
	}

	public BigInteger getS() {
		return S;
	}

	public void setS(BigInteger s) {
		S = s;
	}


	@Override
	public String toString() {
		return "DhServer [x=" + x + ", g=" + g + ", n=" + n + ", A=" + A
				+ ", B=" + B + ", S=" + S + "]";
	}
	
	

}
